package com.cyf.mq.producer;

import com.cyf.mq.constant.MqConstant;
import lombok.extern.slf4j.Slf4j;
import org.apache.rocketmq.client.producer.DefaultMQProducer;
import org.apache.rocketmq.client.producer.SendResult;
import org.apache.rocketmq.common.message.Message;
import java.util.UUID;

/**
 * @author chenyifan
 * @create 2025-02-20 10:45
 */
@Slf4j
public class RetryProducer {

    public static void main(String[] args) throws Exception {
        DefaultMQProducer producer = new DefaultMQProducer(MqConstant.MESSAGE_PRODUCER_GROUP_A);
        producer.setNamesrvAddr(MqConstant.NAME_SERVER_ADDR);
        producer.start();

        // 生产者发送消息 重试的次数
        producer.setRetryTimesWhenSendAsyncFailed(2);
        producer.setRetryTimesWhenSendFailed(2);

        String key = UUID.randomUUID().toString();
        Message message = new Message(MqConstant.MESSAGE_TOPIC_King, null, key, "vip文章".getBytes());
        SendResult sendResult = producer.send(message);
        log.info("发送结果：{}", sendResult);
//        producer.shutdown();
        System.in.read();
    }
}